
var _appPath = "";

function mbinfo(c) {
  if(c) openWin(_appPath+"/memberInfo/info?memberCode="+c, 420, 300);
}


var _shopls = null;
var _areals = null;
var _areatp = null;
var _shopselnum = 0;
function shopsel(name) {
  var ss = '<div id="dv_shopsel" class="shopsel" style="display:none;" onclick="eventCancel(event);"></div>'
      + '<input type="hidden" id="isel_shopcode" name="'+name+'" value=""><input type="text" id="isel_shopname" class="disable" readonly value="">';
  document.write(ss);
  getJson(_appPath+"/getUserShop", function(data){
    if(data.ret && data.data) {
      _shopls = data.data.shops;
      _areals = data.data.areas;
      _areatp = data.data.areatp;
      slpinit();
    }
  });
}
function slpinit() {
  if(!_shopls || _shopls.length==0) return;
  var i, j, shop, ipt;
  if(_shopls.length==1) {
    shop = _shopls[0];
    ipt = getEl("isel_shopcode");
    if(ipt) ipt.value = shop[0];
    ipt = getEl("isel_shopname");
    if(ipt) ipt.value = shop[0]+'-'+shop[1];
  } else {
    ipt = getEl("isel_shopname");
    if(ipt) {
      ipt.value = "全部"+_shopls.length+"家门店";
      ipt.className = "disable dropdown";
      ipt.onclick = slpshow;
    }
    var arr = [];
    arr.push('<div id="dv_selhd" class="selhd"><input type="button" class="sel" value="选择门店" onclick="slpchg(0);" />');
    for(i=0; _areatp && i<_areatp.length; i++)
      arr.push('<input type="button" value="'+_areatp[i][1]+'区域" onclick="slpchg('+(i+1)+');" />');
    arr.push('</div>');
    arr.push('<div id="dv_sels_0"><div class="selqy">输入关键字：<input type="text" onkeyup="slpfdsh(this.value);"></div><div id="dv_selsh" class="selsh">');
    for(i=0; i<_shopls.length; i++)
      arr.push('<label><input type="checkbox" id="cb_slp_shop_'+_shopls[i][0]+'" value="'+_shopls[i][0]+'" checked onclick="slpselsh(this);" kw="'+_shopls[i][0]+'/'+_shopls[i][1]+'/'+_shopls[i][2]+'"><span>'+_shopls[i][0]+'-'+_shopls[i][1]+'</span></label>');
    arr.push('</div></div>');
    for(j=0; _areatp && j<_areatp.length; j++) {
      arr.push('<div id="dv_sels_'+(j+1)+'" class="selar" style="display:none;">');
      for(i=0; i<_areals.length; i++)
        if(_areals[i][2]==_areatp[j][0])
          arr.push('<label><input type="checkbox" value="'+_areals[i][0]+'" checked onclick="slpselar(this);">'+_areals[i][1]+'('+_areals[i][3].length+')</label>');
      arr.push('</div>');
    }
    arr.push('<div class="selft"><span style="margin-right:10px;">选择了<span id="sp_selst">全部'+_shopls.length+'</span>家门店</span>'
        + '<input type="button" value="全选" onclick="slpselall();"><input type="button" value="全清" onclick="slpselnone();">'
        + '<input type="button" class="button" value="确定" onclick="slpselok();"></div>');
    var div = getEl('dv_shopsel');
    if(div) div.innerHTML = arr.join('');

    _shopselnum = _shopls.length;
  }
}
function slpshowsln() {
  var sp = getEl("sp_selst");
  if(sp) sp.innerHTML = (_shopselnum==_shopls.length?'全部':'')+_shopselnum;
}
function slpshow(e) {
  var div = getEl('dv_shopsel');
  if(div) div.style.display = "";
  e.cancelBubble = true;
  document.onclick = slpdmclick;
}
function slpclose() {
  var div = getEl('dv_shopsel');
  if(div) div.style.display = "none";
  document.onclick = null;
}
function slpdmclick(e) {
  var el;
  if(window.event)
    el = event.srcElement;
  else
    el = e.target;
  var ipt = getEl("isel_shopname");
  if(el!=ipt) {
    slpclose();
  }
}
function slpchg(t) {
  var div = getEl("dv_selhd");
  if(!div) return;
  for(var i=0; i<div.childNodes.length; i++) {
    div.childNodes[i].className = t==i?"sel":"";
    getEl("dv_sels_"+i).style.display = t==i?"":"none";
  }
}
function slpselall() {
  var div = getEl("dv_selsh");
  if(!div) return;
  var i,j;
  for(i=0; i<div.childNodes.length; i++) {
    div.childNodes[i].childNodes[0].checked = true;
  }
  for(j=0; _areatp && j<_areatp.length; j++) {
    div = getEl("dv_sels_"+(j+1));
    for(i=0; i<div.childNodes.length; i++) {
      div.childNodes[i].childNodes[0].checked = true;
    }
  }
  _shopselnum = _shopls.length;
  slpshowsln();
}
function slpselnone() {
  var div = getEl("dv_selsh");
  if(!div) return;
  var i,j;
  for(i=0; i<div.childNodes.length; i++) {
    div.childNodes[i].childNodes[0].checked = false;
  }
  for(j=0; _areatp && j<_areatp.length; j++) {
    div = getEl("dv_sels_"+(j+1));
    for(i=0; i<div.childNodes.length; i++) {
      div.childNodes[i].childNodes[0].checked = false;
    }
  }
  _shopselnum = 0;
  slpshowsln();
}
function slpfdsh(v) {
  var div = getEl("dv_selsh");
  if(!div) return;
  var i,kw;
  for(i=0; i<div.childNodes.length; i++) {
    kw = div.childNodes[i].childNodes[0].getAttribute("kw");
    div.childNodes[i].style.display = (kw.indexOf(v)>=0)?"":"none";
  }
}
function slpselsh(cb) {
  if(cb.checked) {
    _shopselnum++;
  } else {
    _shopselnum--;
  }
  slpshowsln();
}
function slpselar(cb) {
  var aid = cb.value;
  var i, j, cb1;
  for(j=0; j<_areals.length; j++) {
    if(_areals[j][0]==aid) {
      for(i=0; i<_areals[j][3].length; i++) {
        cb1 = getEl("cb_slp_shop_"+_areals[j][3][i]);
        if(cb1) {
          if(cb.checked && !cb1.checked) {
            cb1.checked = true;
            _shopselnum++;
          } else if(!cb.checked && cb1.checked) {
            cb1.checked = false;
            _shopselnum--;
          }
        }
      }
      break;
    }
  }
  slpshowsln();
}
function slpselok() {
  if(_shopselnum<=0) {
    window.alert("请选择门店!");
    return;
  }
  var ipt = getEl("isel_shopcode");
  if(_shopselnum==_shopls.length) {
    if(ipt) ipt.value = "";
    ipt = getEl("isel_shopname");
    if(ipt) ipt.value = "全部"+_shopselnum+"家门店";
  } else {
    var div = getEl("dv_selsh");
    if(!div) return;
    var i,nam=null,shs = [];
    for(i=0; i<div.childNodes.length; i++) {
      if(div.childNodes[i].childNodes[0].checked) {
        shs.push(div.childNodes[i].childNodes[0].value);
        if(!nam) nam = div.childNodes[i].childNodes[1].innerHTML;
      }
    }
    if(ipt) ipt.value = shs.join(",");
    ipt = getEl("isel_shopname");
    if(ipt) {
      if(shs.length==1) {
        ipt.value = nam;
      } else {
        ipt.value = "已选"+_shopselnum+"家门店";
      }
    }
  }
  slpclose();
}

function eventCancel(e) {
  e.cancelBubble = true;
  //e.returnValue = false;
  //e.cancel = true;
  //return false;
}


function getDtStr(dt) {
  return dt.getFullYear()+"-"+(dt.getMonth()<9?"0":"")+(dt.getMonth()+1)+"-"+(dt.getDate()<10?"0":"")+dt.getDate()+" "+(dt.getHours()<10?"0":"")+dt.getHours()+":"+(dt.getMinutes()<10?"0":"")+dt.getMinutes();
}

function getDateStr(dt) {
  return dt.getFullYear()+"-"+(dt.getMonth()<9?"0":"")+(dt.getMonth()+1)+"-"+(dt.getDate()<10?"0":"")+dt.getDate();
}

function parseDate(dt) {
  var tt = dt.split("-");
  if(tt.length<3) return null;
  return new Date(parseInt(tt[0],10), parseInt(tt[1],10)-1, parseInt(tt[2],10));
}

Date.prototype.addDay = function(d) {
  this.setDate(this.getDate() + d);
}

Date.prototype.addWeek = function(w) {
  this.setDate(this.getDate() + w*7);
}

Date.prototype.addMonth = function(m) {
  var d = this.getDate();
  this.setMonth(this.getMonth() + m);

  if (this.getDate() < d)
    this.setDate(0);
}

Date.prototype.addYear = function(y) {
  var m = this.getMonth();
  this.setFullYear(this.getFullYear() + y);

  if (m < this.getMonth())
    this.setDate(0);
}

function formatMoney(s) {
  /*var n = 2;
  s = parseFloat((s+"").replace(/[^\d\.-]/g,"")).toFixed(n)+"";
  var l = s.split(".")[0].split("").reverse();
  var r = s.split(".")[1];
  var t = "";
  for(i = 0;i<l.length;i++){
    t += l[i]+((i+1)%3==0 && (i+1) != l.length ? "," : "");
  }
  return t.split("").reverse().join("")+"."+r;*/
  return parseFloat((s+"").replace(/[^\d\.-]/g,"")).toFixed(2);
}


var _pgno = 1;
function query() {
  var fm = getEl("fm_query");
  if(fm) {
    _pgno = 1;
    loadForm("div_list", fm.action, fm, null, function(){
      //getEl("div_list").innerHTML = "<span class='loading'></span>正在查询,请稍等...";
      return true;
    });
  }
}

function topage(pg) {
  var fm = getEl("fm_query");
  if(fm) {
    _pgno = pg;
    loadForm("div_list", fm.action, fm, null, function(){
      //getEl("div_list").innerHTML = "<span class='loading'></span>正在查询,请稍等...";
      return true;
    }, "pageNo="+pg);
  }
}

function reloadlist() {
  topage(_pgno);
}

function pagekeydown(e, pg) {
  var keyc;
  if(window.event)
    keyc = event.keyCode;
  else
    keyc = e.which;
  if(keyc==13) topage(pg);
}

function expt() {
  var fm = getEl("fm_query");
  if(fm) {
    var pm = getFormData(fm);
    if(!pm) return;
    var url = "expt?"+pm.join("&")
    wopen(url);
  }
}

var wopen = window.open;
window.open = function(url, b) {
  if(window.parent && window.parent.fmshow)
    window.parent.fmshow(getAbsUrl(url), window.frameElement, b);
  else
    window.wopen(url);
}
window.fmshow = function(url) {
  if(window.parent && window!=window.parent && window.parent.fmshow)
    window.parent.fmshow(getAbsUrl(url), window.frameElement);
  else
    window.wopen(url);
}

function open2(url, fncb) {
  loadHtml("div_edit", url, null, open2Ret, fncb);
}
function open2Ret(fncb) {
  var div = getEl("div_main");
  if(div) div.style.display = "none";
  div = getEl("div_edit");
  if(div) div.style.display = "";
  if(fncb) fncb();
}

function post(fm, chk) {
  postForm(fm.action, fm, postRet, chk);
  return false;
}
function postRet(data) {
  window.alert(data.msg);
  if(data.ret) cload();
}

function post2(fm, chk) {
  postForm(fm.action, fm, post2Ret, chk);
  return false;
}
function post2Ret(data) {
  window.alert(data.msg);
  if(data.ret) {
    reloadlist();
    backList();
  }
}

function cconfirm(url) {
    oper(url);
}

function cdel(url) {
  if(window.confirm("确定要删除吗?"))
    oper(url);
}
function enable(pmid, b) {
  oper("_enable?"+pmid+"&enable="+b);
}
function oper(url) {
  getJson(url, operRet);
}
function operRet(data) {
  window.alert(data.msg);
  reloadlist();
  backList();
}

function backList() {
  var div = getEl("div_edit");
  if(div) div.style.display = "none";
  div = getEl("div_main");
  if(div) div.style.display = "";
}

function cload() {
  if(window.parent && window.parent.fmcload) {
    window.parent.fmcload(window.frameElement);
  } else {
    if(window.parent && window.parent.reloadlist) window.parent.reloadlist();
    window.close();
  }
}

var wclose = window.close;
window.close = function() {
  if(window.parent && window.parent.fmclosf) {
    window.parent.fmclosf(window.frameElement);
  } else {
    window.wclose();
  }
}

/*function focusFirst() {
  try {
    var ipts = document.getElementsByTagName("INPUT");
    if(ipts && ipts.length>0) {
      for(var i=0; i<ipts.length; i++) {
        if(ipts[i].type=="text") {
          ipts[i].focus();
          break;
        }
      }
    }
  } catch(e) {}
}
if(window.attachEvent)
  window.attachEvent("onload", focusFirst);
else if(window.addEventListener)
  window.addEventListener("load", focusFirst, false);*/

function getParentWin() {
  if(window.parent && window.parent.getParentFrameWin) {
    return window.parent.getParentFrameWin(window.frameElement);
  } else {
    if(window.parent && window.parent)
      return window.parent;
    else if(window.opener && window.opener)
      return window.opener;
  }
}

function getAbsUrl(url) {
  if(url.length>1 && url.substring(0,1)=='/')
    return url;
  else if(url.length>5 && url.substring(0,4)=='http')
    return url;
  var p = document.location.href;
  return p.substring(0, p.lastIndexOf("/")+1) + url;
  //return url;
}

function fold(t, eid, eid2) {
  var div = document.getElementById(eid);
  if(!div) return;
  var b = div.style.display=="none";
  div.style.display = b?"":"none";
  t.className = b?"unfold":"fold";
  t.innerHTML = b?"隐藏":"显示";
  if(eid2) {
    div = document.getElementById(eid2);
    if(div) div.style.display = b?"none":"";
  }
}

var getFormData = function(fm, chk) {
  var i, el, tips, vtp, pm=[];
  for(i=0; i<fm.elements.length; i++) {
    el = fm.elements[i];
    if(el.tagName=="INPUT" || el.tagName=="SELECT" || el.tagName=="TEXTAREA") {
      if(el.tagName=="INPUT" && (el.type=="radio" || el.type=="checkbox")) {
        if(!el.checked) continue;
      }
      if(el.value=="") {
        tips = el.getAttribute("req");
        if(tips) {
          window.alert("请"+(el.tagName=="SELECT"?"选择":"输入")+tips+"!");
          try {el.focus();} catch(e) {}
          return null;
        }
      }
      vtp = el.getAttribute("vtp");
      if(vtp!="" && el.value!="") {
        if(!chkValueType(el.value, vtp)) {
          try {el.focus();} catch(e) {}
          return null;
        }
      }
      if(el.name) pm.push(el.name+"="+encodeURIComponent(el.value));
    }
  }
  if(chk && !chk()) return null;
  return pm;
}
function chkValueType(v, tp) {
  if(tp=="email" && !isEmail(v)) {
    window.alert("请输入正确的邮箱地址!");
  } else if(tp=="mobile" && !isMobile(v)) {
    window.alert("请输入正确的手机号码!");
  } else if(tp=="int" && !isInt(v)) {
    window.alert("请输入整数!");
  } else if(tp=="number" && isNaN(v)) {
    window.alert("请输入数字!");
  } else if(tp=="idNumber" && !isIdNumber(v)) {
    window.alert("请输入正确的身份证号码!");
  } else {
    return true;
  }
  return false;
}
function isEmail(email) {
  var myReg = /^[_a-zA-Z0-9+\.]+@([\-_a-zA-Z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
  if(myReg.test(email)) return true;
  return false;
}
function isMobile(txt) {
  return (/^(1)\d{10}$/.test(txt));
}
function isInt(v) {
  return (/^[1-9]\d*|0$/.test(v));
}
function isIdNumber(idcard){
  var area= {11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
  var ereg,Y,JYM;
  var S,M;
  var idcard_array = new Array();
  idcard_array = idcard.split("");
  //地区检验
  if(area[parseInt(idcard.substr(0,2))]==null) return false;
  //身份号码位数及格式检验
  switch(idcard.length){
    case 15:
      if ((parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
        ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
      } else {
        ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
      }
      if(ereg.test(idcard))
        return true;
      else
        return false;
      break;
    case 18:
      //18位身份号码检测
      //出生日期的合法性检查
      //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))
      //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))
      if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
        ereg=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
      } else {
        ereg=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
      }
      if(ereg.test(idcard)){//测试出生日期的合法性
        //计算校验位
        S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
            + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
            + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
            + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
            + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
            + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
            + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
            + parseInt(idcard_array[7]) * 1
            + parseInt(idcard_array[8]) * 6
            + parseInt(idcard_array[9]) * 3 ;
        Y = S % 11;
        M = "F";
        JYM = "10X98765432";
        if(idcard_array[17] == 'x'){
          JYM = "10x98765432";
        }
        M = JYM.substr(Y,1);//判断校验位
        if(M == idcard_array[17])
          return true; //检测ID的校验位
        else
          return false;
      } else
        return false;
    default:
      return false;
  }
}

var postForm = function(url, fm, fncb, chk) {
  var pm=getFormData(fm, chk);
  if(!pm) return false;
  callAjax(url, pm.join("&"), fncb, null, null, "json");
  return true;
}

var getJson = function(url, fncb, param) {
  callAjax(url, null, fncb, param, null, "json");
}
var postJson = function(url, dat, fncb, param) {
  callAjax(url, dat, fncb, param, null, "json");
}

var loadForm = function(dvid, url, fm, fncb, chk, pm2) {
  var pm=getFormData(fm, chk);
  if(!pm) return false;
  if(pm2) pm.push(pm2);
  callAjax(url, pm.join("&"), loadFormRet, [dvid, fncb]);
  return true;
}

var loadFormRet = function(data, pm) {
  var dv = document.getElementById(pm[0]);
  if(dv) dv.innerHTML = data;
  if(pm[1])
    pm[1]();
  else if(typeof(loadcbfn)=="function")
    loadcbfn();
}

var loadHtml = function(dvid, url, dat, fncb, pm) {
  callAjax(url, dat, loadHtmlRet, [dvid, fncb, pm]);
}
var loadHtmlRet = function(data, pm) {
  var dv = document.getElementById(pm[0]);
  if(dv) dv.innerHTML = data;
  if(pm[1]) pm[1](pm[2]);
}

var getEl = function(eid) {
  return document.getElementById(eid);
}

var toJson = function(data) {
  if(data=="") return null;
  eval("var d = "+data);
  return d;
}

var callAjax = function(url, dat, fncb, param, fnfl, ct) {
  var http, med, curl;
  if(window.XMLHttpRequest)
    http = new XMLHttpRequest();
  else
    http = new ActiveXObject("Microsoft.XMLHTTP");
  if(dat) {
    med = "POST";
    curl = url;
  } else {
    med = "GET";
    curl = url + (url.indexOf("?")>=0?"&":"?") + "_r="+(new Date()).getTime();
  }
  http.open(med, curl, true);
  http.onreadystatechange = function(){
      callAjaxReadyState(http, fncb, param, fnfl, ct);
    };
  http.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  if(med=="POST") {
    http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    http.send(dat);
  } else {
    http.send(null);
  }
}
var callAjaxReadyState = function(http, fncb, param, fnfl, ct) {
  if(http.readyState == 4) {
    if(http.status==200 || http.status==0) {
      var data = null;
      try {
        if(ct=="xml" || ct=="xmlObj" || (!ct && http.getResponseHeader("Content-Type").indexOf("text/xml")>=0)) {
          data = http.responseXML;
        } else {
          data = http.responseText;
          if(ct=="json" || http.getResponseHeader("Content-Type").indexOf("text/json")>=0) data = toJson(data);
        }
        if(data)
          if(fncb) fncb(data, param);
        else
          if(fnfl) fnfl(http.status, "nodata", param);
      } catch (e) {
        if(fnfl)
          fnfl(e.name, e.message, param);
        else
          callErr(e.name, e.message, param);
      }
    } else if(http.status==401) {
      if(window.parent && window.parent.showLogin) {
        window.parent.showLogin(true);
      } else {
        window.alert('请重新登录');
      }
    } else if(http.status==403) {
      window.alert('没有权限执行该操作');
    } else{
      if(fnfl)
        fnfl(http.status, http.statusText, param);
      else
        callErr(http.status, http.statusText, param);
    }
  }
}

var callErr = function(stat, msg, param) {
  window.alert(stat+"-"+msg);
}


function initOpenWin() {
  var ss = '<div id="div_fullbg" class="fullbg" style="display:none;"></div>'
      + '<div id="div_openwin" class="openwin" style="display:none;">'
      + '<dl><dt><span></span><a href="javascript:closeWin();">×</a></dt>'
      + '<dd><iframe width="100%" frameborder="0" scrolling="auto" src="about:blank;" onload="winsett(this);"></iframe></dd></dl>'
      + '</div>';
  document.write(ss);
}

function openWin(url, wid, hei) {
  var div = getEl("div_openwin");
  if(!div) return;
  var w = wid||500;
  var h = hei||400;
  div.style.width = w+"px";
  div.style.marginLeft = (-w/2-10)+"px";
  div.style.marginTop = (-h/2-20)+"px";
  var dl = div.firstChild;
  dl.firstChild.firstChild.innerHTML = '<img src="/images/ic_loading.gif">正在加载...</span>';
  var ifm = dl.childNodes[1].firstChild;
  ifm.src = url;
  ifm.style.height = h+"px";
  div.style.display = "";
  div = getEl("div_fullbg");
  if(div) div.style.display = "";
}

function closeWin() {
  var div = getEl("div_openwin");
  if(div) {
    var w = div.firstChild.childNodes[1].firstChild.contentWindow;
    if(w && w.chkClose && !w.chkClose()) return;
    div.style.display = "none";
    div.firstChild.childNodes[1].firstChild.src = "about:blank";
  }
  div = getEl("div_fullbg");
  if(div) div.style.display = "none";
}

function winsett(f) {
  var tt = '';
  try {
    tt = f.contentWindow.document.title;
  } catch(e) {}
  var div = document.getElementById("div_openwin");
  if(div) {
    div.firstChild.firstChild.firstChild.innerHTML = tt;
  }
}

initOpenWin();





function getMoneyCn0(m){
  return moneyInWords(m, 0);
}

function moneyInWords(dValue, maxDec)
{
// 验证输入金额数值或数值字符串：
  dValue = dValue.toString().replace(/[^\d\.-]/g, ""); dValue = dValue.replace(/^0+/, "");      // 金额数值转字符、移除逗号、移除前导零
  if (dValue == "") { return "零"; }      // （错误：金额为空！）
  else if (isNaN(dValue)) { return "错误：金额不是合法的数值！"; }

  var minus = "";                             // 负数的符号“-”的大写：“负”字。可自定义字符，如“（负）”。
  var CN_SYMBOL = "";                         // 币种名称（如“人民币”，默认空）
  if (dValue.length > 1)
  {
    if (dValue.indexOf('-') == 0) { dValue = dValue.replace("-", ""); minus = "负"; }   // 处理负数符号“-”
    if (dValue.indexOf('+') == 0) { dValue = dValue.replace("+", ""); }                 // 处理前导正数符号“+”（无实际意义）
  }

// 变量定义：
  var vInt = ""; var vDec = "";               // 字符串：金额的整数部分、小数部分
  var resAIW;                                 // 字符串：要输出的结果
  var parts;                                  // 数组（整数部分.小数部分），length=1时则仅为整数。
  var digits, radices, bigRadices, decimals; // 数组：数字（0~9——零~玖）；基（十进制记数系统中每个数字位的基是10——拾,佰,仟）；大基（万,亿,兆,京,垓,杼,穰,沟,涧,正）；辅币 （元以下，角/分/厘/毫/丝）。
  var zeroCount;                              // 零计数
  var i, p, d;                                // 循环因子；前一位数字；当前位数字。
  var quotient, modulus;                      // 整数部分计算用：商数、模数。

  // 金额数值转换为字符，分割整数部分和小数部分：整数、小数分开来搞（小数部分有可能四舍五入后对整数部分有进位）。
  var NoneDecLen = (typeof(maxDec) == "undefined" || maxDec == null || Number(maxDec) < 0 || Number(maxDec) > 5);     // 是否未指定有效小数位（true/false）
  parts = dValue.split('.');                      // 数组赋值：（整数部分.小数部分），Array的length=1则仅为整数。
  if (parts.length > 1)
  {
    vInt = parts[0]; vDec = parts[1];           // 变量赋值：金额的整数部分、小数部分

    if(NoneDecLen) { maxDec = vDec.length > 5 ? 5 : vDec.length; }                                  // 未指定有效小数位参数值时，自动取实际小数位长但不超5。
    var rDec = Number("0." + vDec);
    rDec *= Math.pow(10, maxDec); rDec = Math.round(Math.abs(rDec)); rDec /= Math.pow(10, maxDec); // 小数四舍五入
    var aIntDec = rDec.toString().split('.');
    if(Number(aIntDec[0]) == 1) { vInt = (Number(vInt) + 1).toString(); }                           // 小数部分四舍五入后有可能向整数部分的个位进位（值1）
    if(aIntDec.length > 1) { vDec = aIntDec[1]; } else { vDec = ""; }
  }
  else { vInt = dValue; vDec = ""; if(NoneDecLen) { maxDec = 0; } }
  if(vInt.length > 44) { return "错误：金额值太大了！整数位长【" + vInt.length.toString() + "】超过了上限——44位/千正/10^43（注：1正=1万涧=1亿亿亿亿亿，10^40）！"; }

// 准备各字符数组 Prepare the characters corresponding to the digits:
  digits = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");         // 零~玖
  radices = new Array("", "拾", "佰", "仟");                                              // 拾,佰,仟
  bigRadices = new Array("", "万", "亿", "兆", "京", "垓", "杼", "穰" ,"沟", "涧", "正"); // 万,亿,兆,京,垓,杼,穰,沟,涧,正
  decimals = new Array("角", "分", "厘", "毫", "丝");                                     // 角/分/厘/毫/丝

  resAIW = ""; // 开始处理

// 处理整数部分（如果有）
  if (Number(vInt) > 0)
  {
    zeroCount = 0;
    for (i = 0; i < vInt.length; i++)
    {
      p = vInt.length - i - 1; d = vInt.substr(i, 1); quotient = p / 4; modulus = p % 4;
      if (d == "0") { zeroCount++; }
      else
      {
        if (zeroCount > 0) { resAIW += digits[0]; }
        zeroCount = 0; resAIW += digits[Number(d)] + radices[modulus];
      }
      if (modulus == 0 && zeroCount < 4) { resAIW += bigRadices[quotient]; }
    }
    //resAIW += "元";
  }

// 处理小数部分（如果有）
  for (i = 0; i < vDec.length; i++) { d = vDec.substr(i, 1); if (d != "0") { resAIW += digits[Number(d)] + decimals[i]; } }

// 处理结果
  if (resAIW == "") { resAIW = "零"; }     // 零元
  //if (vDec == "") { resAIW += "整"; }             // ...元整
  resAIW = CN_SYMBOL + minus + resAIW;            // 人民币/负......元角分/整
  return resAIW;
}

